package com.zhou.base.components.feign.cloud.nacoslistener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

/**
 * @author xianfeng
 * @date 2023/12/1 16:03
 * @description:
 */
@Slf4j
@Service
public class NacosListener implements ApplicationListener<EnvironmentChangeEvent> {

    private static final String testParamKey = "test.param";

    @Value("${" + testParamKey + "}")
    private String testParam;

    @Override
    public void onApplicationEvent(EnvironmentChangeEvent event) {
        boolean contains = event.getKeys().contains("");
        if (event.getKeys().contains(testParamKey)) {
            log.info("key({})发生了变化({})", testParamKey, testParam);
        }
    }
}
